package com.xy.biz.uc.domain.converter;

import java.util.Collection;
import java.util.List;

import com.xy.tool.util.BeanUtilsEx;
import com.xy.biz.uc.domain.bo.RoleBO;
import com.xy.biz.uc.domain.po.RolePO;
import com.xy.biz.uc.domain.query.RoleQuery;
import com.xy.biz.uc.domain.dto.RoleDTO;
import com.xy.biz.uc.domain.req.SaveRoleRequest;
import com.xy.biz.uc.domain.req.ListRoleRequest;

/**
 * 
 * 
 * @author zsp
 * @date 2020-8-19
 */
public class RoleConverter {
	
	public static RolePO toPO(RoleBO source) {
		return BeanUtilsEx.copyProperties(source, () -> new RolePO(), true);
	}
	
	public static List<RolePO> toPO(Collection<RoleBO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new RolePO(), true);
	}
	
	public static RoleBO fromPO(RolePO source) {
		return BeanUtilsEx.copyProperties(source, () -> new RoleBO());
	}
	
	public static List<RoleBO> fromPO(Collection<RolePO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new RoleBO());
	}
	
	public static RoleBO toBO(SaveRoleRequest source) {
		return BeanUtilsEx.copyProperties(source, () -> new RoleBO(), true);
	}
	
	public static List<RoleBO> toBO(Collection<SaveRoleRequest> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new RoleBO(), true);
	}
	
	public static RoleDTO toDTO(RoleBO source) {
		return BeanUtilsEx.copyProperties(source, () -> new RoleDTO());
	}
	
	public static List<RoleDTO> toDTO(Collection<RoleBO> source) {
		return BeanUtilsEx.copyPropertiesForNewList(source, () -> new RoleDTO());
	}
	
	public static RoleQuery toQuery(ListRoleRequest source) {
		if(null == source) {
			return null;
		}
		RoleQuery target = new RoleQuery(source.getPageIndex(), source.getPageSize());
		BeanUtilsEx.copyProperties(source, target);
		return target;
	}

}
